package com.run.wz.center.hbase.actionbuilder.impl;

import java.text.ParseException;
import java.util.TreeSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Scan;

import com.run.wz.center.hbase.actionbuilder.HbaseActionBuilder;
import com.run.wz.center.util.ObjectType;
import com.run.wz.center.utils.ProtocolType;
/**
 * scan构建的一个抽象实现，这里是实现了一个构建scan的方法
 * 具体的 {@link HbaseActionBuilder#build()} 方法保留抽象留给
 * 具体的子类去实现。
 * 
 * 增加 {@link #buildScans(HTableDescriptor)} 抽象方法，由子类
 * 根据不同的需求实现不同的逻辑。
 * @author chenxu 2012-9-12 上午10:53:19
 *
 */
public abstract class ScanBuilder implements HbaseActionBuilder<String, TreeSet<Scan>>{

	protected static Log logger = LogFactory.getLog(ScanBuilder.class);

	public ScanBuilder(String oid, ObjectType objectType) {
		super();
		this.oid = oid;
		this.objectType = objectType;
	}

	protected String oid;
	protected ObjectType objectType;

	/**
	 * 
	 * chenxu 2012-9-7 下午1:51:08
	 * @return
	 */
	protected Scan buildScan() {
		
		Scan scan = new Scan();
		scan.setCaching(20000);
		
		byte[][] startStopRow = objectType.getStartStopRow(oid);
		byte[] startBytes = startStopRow[0];
		byte[] endBytes = startStopRow[1];
		scan.setStartRow(startBytes);
		scan.setStopRow(endBytes);
		return scan;
	
	}
	
	public abstract TreeSet<Scan> buildScans(HTableDescriptor htd,TreeSet<ProtocolType> protocolTypeSet) throws ParseException ;

}